package com.ruoyi.mes.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mes.domain.QualityInspectionPlan;
import com.ruoyi.mes.service.IQualityInspectionPlanService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 质检计划管理Controller
 * 
 * @author ruoyi
 * @date 2025-01-09
 */
@RestController
@RequestMapping("/mes/plan")
public class QualityInspectionPlanController extends BaseController
{
    @Autowired
    private IQualityInspectionPlanService qualityInspectionPlanService;

    /**
     * 查询质检计划管理列表
     */
    @PreAuthorize("@ss.hasPermi('mes:plan:list')")
    @GetMapping("/list")
    public TableDataInfo list(QualityInspectionPlan qualityInspectionPlan)
    {
        startPage();
        List<QualityInspectionPlan> list = qualityInspectionPlanService.selectQualityInspectionPlanList(qualityInspectionPlan);
        return getDataTable(list);
    }

    /**
     * 导出质检计划管理列表
     */
    @PreAuthorize("@ss.hasPermi('mes:plan:export')")
    @Log(title = "质检计划管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, QualityInspectionPlan qualityInspectionPlan)
    {
        List<QualityInspectionPlan> list = qualityInspectionPlanService.selectQualityInspectionPlanList(qualityInspectionPlan);
        ExcelUtil<QualityInspectionPlan> util = new ExcelUtil<QualityInspectionPlan>(QualityInspectionPlan.class);
        util.exportExcel(response, list, "质检计划管理数据");
    }

    /**
     * 获取质检计划管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('mes:plan:query')")
    @GetMapping(value = "/{planId}")
    public AjaxResult getInfo(@PathVariable("planId") Long planId)
    {
        return success(qualityInspectionPlanService.selectQualityInspectionPlanByPlanId(planId));
    }

    /**
     * 新增质检计划管理
     */
    @PreAuthorize("@ss.hasPermi('mes:plan:add')")
    @Log(title = "质检计划管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QualityInspectionPlan qualityInspectionPlan)
    {
        return toAjax(qualityInspectionPlanService.insertQualityInspectionPlan(qualityInspectionPlan));
    }

    /**
     * 修改质检计划管理
     */
    @PreAuthorize("@ss.hasPermi('mes:plan:edit')")
    @Log(title = "质检计划管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QualityInspectionPlan qualityInspectionPlan)
    {
        return toAjax(qualityInspectionPlanService.updateQualityInspectionPlan(qualityInspectionPlan));
    }

    /**
     * 删除质检计划管理
     */
    @PreAuthorize("@ss.hasPermi('mes:plan:remove')")
    @Log(title = "质检计划管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{planIds}")
    public AjaxResult remove(@PathVariable Long[] planIds)
    {
        return toAjax(qualityInspectionPlanService.deleteQualityInspectionPlanByPlanIds(planIds));
    }
}
